﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using CoreEx.Common.Proxy;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;
using LinFu.IoC;
using LinFu.Proxy.Interfaces;
using Mono.Cecil;

namespace CoreEx.Common.Implementation.Proxy
{
    //[Implements(typeof(ITypeModifier))]
    public class AddProxyPropertiesModifier : ITypeModifier, IInitialize
    {
        public IPropertyPicker PropertyPicker { get; set; }

        public IExtractInterfaces InterfaceExtractor { get; set; }

        public void BeforeConstruction(Type originalBaseType, IEnumerable<Type> baseInterfaces, ModuleDefinition module, TypeDefinition typeDefinition)
        {
            //Do nothing here
        }

        public void AfterConstruction(Type originalBaseType, IEnumerable<Type> baseInterfaces, ModuleDefinition module, TypeDefinition typeDefinition)
        {
            HashSet<Type> interfaces = new HashSet<Type>();
            InterfaceExtractor.GetInterfaces(originalBaseType, interfaces);
            
            var targetTypes = new List<Type>(new [] {originalBaseType});
            
            targetTypes.AddRange(baseInterfaces);
            var properties = PropertyPicker.ChooseProxyPropertiesFrom(targetTypes);
            foreach (var property in properties)
            {
                var getMethod = property.GetGetMethod();
                var setMethod = property.GetSetMethod();
                    
                
            }
        }

        



        public void Initialize(IServiceContainer source)
        {
            PropertyPicker = source.GetService<IPropertyPicker>();
            InterfaceExtractor = source.GetService<IExtractInterfaces>();
        }
    }
}
